<?php
/**
 * 展会列表
 * Created by dutuwang.net
 * User: adophper <hello@adophper.com>
 * Date: 2018/3/30
 * Time: 17:23
 */

use yii\helpers\Html;

$this->title = Yii::t('common', 'exhibition');
$url = Yii::$app->urlManager->createUrl(['zhanhui/index']);
$url .= strpos($url, '?') ? '&' : '?';
//将查询参数转换成单个变量
extract($params);
?>
<?=Html::cssFile('/static/frontend/css/list.css')?>
<?=Html::cssFile('/static/common/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css')?>
<?=Html::jsFile('/static/common/bootstrap-datetimepicker/js/bootstrap-datetimepicker.js')?>
<?=Html::jsFile('/static/common/js/underscore-min.js')?>
<?=Html::jsFile('/static/frontend/js/swipe.js')?>
<div class="page zhanhui">
    <div class="head_banner_bg" style="background-image: url(/static/frontend/image/zhanhui_bg.jpg)">
        <div class="contBox">
            <div class="news-page-banner clearfix">
                <h2>找展会</h2>
                <div class="pull-right list_head_title_tab flex">
                    <a href="#" class="flex f_center btn_red"><i class="iconfont">&#xe665;</i>展商报名</a>
                    <a href="#" class="flex f_center btn_yel"><i class="iconfont">&#xe608;</i>观众登记</a>
                </div>
            </div>
        </div>
    </div>
    <div class="contBox list-page-content">
        <div class="detailBox">
            <form action="<?=$url?>order=<?=$order?>&sort=<?=$sort?>&type=<?=$type?>" method="get" id="search-form">
            <div class="form-inline zhuanhui-title detailBox_title fbox clearfix">
                <label class="label btn_black">全部</label>
                <div class="form-group">
                    <label>展会时间</label>
                    <div class="form-control">
                        <div class="input-append date form_datetime">
                            <input size="16" type="text" name="starttime" value="<?=$starttime?>" id="starttime" readonly>
                            <span class="add-on"><i class="iconfont">&#xe61e;</i></span>
                        </div>
                    </div>
                    <span>至</span>
                    <div class="form-control">
                        <div class="input-append date form_datetime">
                            <input size="16" type="text" name="endtime" value="<?=$endtime?>" id="endtime" readonly>
                            <span class="add-on"><i class="iconfont">&#xe61e;</i></span>
                        </div>
                    </div>
                </div>
                <div class="form-group exhibition-category">
                    <label>展会行业</label>
                    <div class="form-control category">
                        <input type="hidden" name="category_id" id="category_id" value="<?=$category_id?>" />
                        <input type="text" name="category_name" id="category_name" value="<?=$category_name?>" readonly placeholder="行业" />
                        <i class="glyphicon glyphicon-th-large"></i>
                    </div>
                </div>
                <div class="form-group exhibition-address">
                    <label>展会地点</label>
                    <div class="form-control city">
                        <input type="hidden" name="city_arr" id="city_arr" value="<?=$city_arr?>" />
                        <input type="text" name="city" id="city" value="<?=$city?>" readonly placeholder="地点" />
                        <i class="glyphicon glyphicon-map-marker"></i>
                    </div>
                </div>
                <div class="pull-right detailBox_title_search">
                    <input type="text" name="keywords" id="keywords" value="<?=$keywords?>" placeholder="请输入查找内容"/>
                    <i class="btn_red iconfont" onclick="searchForm()">&#xe643;</i>
                </div>
            </div>
            <div class="detailBox_whitemin">
                <!--筛选条件-->
                <div class="screen_tab fbox">
                    <span class="fl">
                        <a href="<?=$url?>starttime=<?=$starttime?>&endtime=<?=$endtime?>&category_id=<?=$category_id?>&category_name=<?=$category_name?>&city=<?=$city?>&city_arr=<?=urlencode($city_arr)?>&keywords=<?=$keywords?>&order=&sort=<?=empty($order)&&$sort=='DESC'?'ASC':'DESC'?>" class="flex f_center">
                            <em>综合</em><i class="iconfont <?=empty($order)?'t_red':''?>"><?=empty($order)&&$sort=='ASC'?'&#xe618;':'&#xe607;'?></i>
                        </a>
                    </span>
                    <span class="fl">
                        <a href="<?=$url?>starttime=<?=$starttime?>&endtime=<?=$endtime?>&category_id=<?=$category_id?>&category_name=<?=$category_name?>&city=<?=$city?>&city_arr=<?=urlencode($city_arr)?>&keywords=<?=$keywords?>&order=starttime&sort=<?=$order=='starttime'&&$sort=='DESC'?'ASC':'DESC'?>" class="flex f_center"><em>开展时间</em><i class="iconfont <?=$order=='starttime'?'t_red':''?>"><?=$order=='starttime'&&$sort=='ASC'?'&#xe618;':'&#xe607;'?></i></a>
                    </span>
                    <span class="fl">
                        <a href="<?=$url?>starttime=<?=$starttime?>&endtime=<?=$endtime?>&category_id=<?=$category_id?>&category_name=<?=$category_name?>&city=<?=$city?>&city_arr=<?=urlencode($city_arr)?>&keywords=<?=$keywords?>&order=hot&sort=<?=$order=='hot'&&$sort=='DESC'?'ASC':'DESC'?>" class="flex f_center"><em>热门度</em><i class="iconfont <?=$order=='hot'?'t_red':''?>"><?=$order=='hot'&&$sort=='ASC'?'&#xe618;':'&#xe607;'?></i></a>
                    </span>
                    <span class="fl">
                        <a href="<?=$url?>starttime=<?=$starttime?>&endtime=<?=$endtime?>&category_id=<?=$category_id?>&category_name=<?=$category_name?>&city=<?=$city?>&city_arr=<?=urlencode($city_arr)?>&keywords=<?=$keywords?>&order=audience_number&sort=<?=$order=='audience_number'&&$sort=='DESC'?'ASC':'DESC'?>" class="flex f_center"><em>观众数量</em><i class="iconfont <?=$order=='audience_number'?'t_red':''?>"><?=$order=='audience_number'&&$sort=='ASC'?'&#xe618;':'&#xe607;'?></i></a>
                    </span>
                    <span class="fl">
                        <a href="<?=$url?>starttime=<?=$starttime?>&endtime=<?=$endtime?>&category_id=<?=$category_id?>&category_name=<?=$category_name?>&city=<?=$city?>&city_arr=<?=urlencode($city_arr)?>&keywords=<?=$keywords?>&order=comments_number&sort=<?=$order=='comments_number'&&$sort=='DESC'?'ASC':'DESC'?>" class="flex f_center"><em>点评数量</em><i class="iconfont <?=$order=='comments_number'?'t_red':''?>"><?=$order=='comments_number'&&$sort=='ASC'?'&#xe618;':'&#xe607;'?></i></a>
                    </span>
                    <span class="fl check">
                        <label class="flex f_center"><input type="checkbox" name="over" value="1" <?=$over?'checked="checked"':''?> onchange="searchForm()" /><em>已结束</em></label>
                    </span>
                    <div class="pull-right">
                        <a href="<?=$url?>starttime=<?=$starttime?>&endtime=<?=$endtime?>&category_id=<?=$category_id?>&category_name=<?=$category_name?>&city=<?=$city?>&city_arr=<?=urlencode($city_arr)?>&keywords=<?=$keywords?>&order=<?=$order?>&sort=<?=$sort?>&type=icon"><i class="glyphicon glyphicon-th-large <?=$type=='icon'?'t_red':''?>" title="图标"></i></a>
                        <a href="<?=$url?>starttime=<?=$starttime?>&endtime=<?=$endtime?>&category_id=<?=$category_id?>&category_name=<?=$category_name?>&city=<?=$city?>&city_arr=<?=urlencode($city_arr)?>&keywords=<?=$keywords?>&order=<?=$order?>&sort=<?=$sort?>&type=list"><i class="glyphicon glyphicon-th-list <?=$type=='list'?'t_red':''?>" title="列表"></i></a>
                    </div>
                </div>
            </div>
            </form>
            <!--列表内容-->
            <?=$this->render($type, [
                'data' => $data,
                'compareData' => $compareData,
            ])?>
        </div>
    </div>
    <!--底部推荐-->
    <div class="contBox">
        <div class="list_foot_remomed_box">
            <p class="list_foot_remomed_title f_relative">
                您可能感兴趣的
                <span id="interest">
                    <?php
                    if (!empty($related)) {
                        $i = 1;
                    foreach ($related as $k => $val) {
                        if ($i%8 == 1) {
                            ?>
                            <i class="<?= $i == 1 ? 'on' : '' ?>"></i>
                            <?php
                        }
                        $i++;
                        }
                    }
                    ?>
                </span>
            </p>
            <div class="list_foot_remomed_list">
                <?php
                if (!empty($related)) {
                ?>
                <div class="swipe" id="slider">
                    <div class="swipe-wrap">
                        <div class="row">
                <?php
                $i = 1;
                    foreach ($related as $val) {
                ?>
                            <div class="col-md-3 col-sm-4 list_foot_remomed_item flex f_relative">
                                <a href="<?=Yii::$app->urlManager->createUrl(['zhanhui/detail', 'id' => $val['id']])?>"><img src="<?=$val['litpic']?>_86x75.jpg" alt="<?=$val['title']?>" /></a>
                                <div>
                                    <a href="<?=Yii::$app->urlManager->createUrl(['zhanhui/detail', 'id' => $val['id']])?>" class="t_o" title="<?=$val['title']?>"><?=$val['title']?></a>
                                    <p class="t_o">时间：<?=date('Y-m-d', $val['starttime'])?></p>
                                    <p class="t_o">场馆：<a href="<?=Yii::$app->urlManager->createUrl(['hall/detail', 'id' => $val['hall_id']])?>"><?=$val['hall_title']?></a></p>
                                </div>
                            </div>
                <?php
                        if ($i%8 ==0 && $i < count($related)) {
                    ?>
                    </div><div class="row">
                    <?php
                        }
                        $i++;
                    }
                ?>
                        </div>
                    </div>
                </div>
                <?php
                }
                ?>
            </div>

            <script>
                /*推荐城市展馆*/
                var slider = Swipe(document.getElementById('slider'), {
                    auto: 3000,
                    continuous: true,
                    callback: function(pos) {
                        var i = bullets.length;
                        while (i--) {
                            bullets[i].className = ' ';
                        }
                        bullets[pos].className = 'on';
                    }
                });
                var bullets = document.getElementById('interest').getElementsByTagName('i');
            </script>
        </div>
    </div>
</div>
<?=$this->render('compare-tpl')?>
<script>
    $(function () {
        $(".form_datetime").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            //showMeridian: false,
            autoclose: true,
            todayBtn: true,
            language: 'zh'
        });

        $(".category").on('click', function (e) {
            var category_id = $("#category_id").val();
            $("#formModal").find(".modal-body").empty();
            $.get('<?=Yii::$app->urlManager->createUrl(['zhanhui/get-category'])?>', {category_id: category_id}, function (response) {
                showDialog('formModal', '选择行业', response);
            })
        })

        $(".city").on('click', function (e) {
            var city_arr = $("#city_arr").val();
            $("#formModal").find(".modal-body").empty();
            $.get('<?=Yii::$app->urlManager->createUrl(['zhanhui/get-city'])?>', {city_arr: city_arr}, function (response) {
                showDialog('formModal', '选择地点', response);
            })
        })
        //city.php选择城市
        $(document).on('click', ".city-select-list span", function (e) {
            var id = $(this).data('id');
            $(".city-select-list").find("span[data-id="+id+"]").remove();
            $(".select-city[data-id='"+id+"']").find("span").removeClass('act')
            if ($(".city-select-list").find("span").length == 0){
                $(".city-select-list").hide();
            }

        })
        //搜索框回车事件
        $("#keywords").keypress(function (e) {
            if (e.keyCode == 13) {
                return false;
            }
        })
    })

    function searchForm(){
        var starttime = $("#starttime").val();
        var endtime = $("#endtime").val();
        if (starttime && endtime) {
            var date_s = new Date(starttime).getTime();
            var date_e = new Date(endtime).getTime();
            if (date_e < date_s) {
                alert('展会开始时间不能在于结束时间');
                return false;
            }
        }
        $("#search-form").submit();
    }

    function showDialog(id, title, content) {
        $("#"+id).find('.modal-footer').find(".btn-primary").unbind('click');
        $("#"+id).find(".modal-title").html(title);
        $("#"+id).find(".modal-body").html(content);
        $("#"+id).modal('show');
    }
</script>